package com.xbongbong.pro.enums.smartsettings.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 智能助手：推送枚举
 *
 * @Author: hongxiao
 * @date: 2019-11-20 15:42
 */
@Getter
public enum AiAssistantPushTypeEnum {
    //******************************************crm***********************************************//
    AI_ASSISTANT_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), 0, "enum.aiAssistantPushType.name.ai_assistant_push", "aiAssistantPush", 0, ""),
    /**
     * CRM
     * 客户 100
     */
    CUSTOMER_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), "enum.aiAssistantPushType.name.customer_push", "aiAssistantCustomerPush", 0, ""),

    /**
     * 联系人 401
     */
    CONTACT_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.CONTACT.getCode(), "enum.aiAssistantPushType.name.contact_push", "aiAssistantContactPush", 0, ""),

    /**
     * 销售机会 301
     */
    OPPORTUNITY_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), "enum.aiAssistantPushType.name.opportunity_push", "aiAssistantOpportunityPush", 0, ""),

    /**
     * 合同  201
     */
    CONTRACT_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.CONTRACT.getCode(), "enum.aiAssistantPushType.name.contract_push","aiAssistantContractPush", 0, ""),
    /**
     * 退货退款 202
     */
    REFUND_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.REFUND.getCode(), "enum.aiAssistantPushType.name.refund_push","aiAssistantRefundPush", 0, ""),
    /**
     * 工作报告 2101
     */
    WORK_REPORT_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.WORK_REPORT.getCode(), "enum.aiAssistantPushType.name.work_report_push", "aiAssistantWorkReportPush", 0, ""),
    /**
     * 报价单 code 4700
     */
    QUOTATION_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.QUOTATION.getCode(), "enum.aiAssistantPushType.name.quotation_push","aiAssistantQuotationPush", 0, ""),


    //******************************************fundManagement***********************************************//
    /**
     * 应收款 701
     */
    PAYMENT_PLAN_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.PAYMENT.getCode(), "enum.aiAssistantPushType.name.payment_plan_push", "aiAssistantPaymentPlanPush", 0, ""),

    /**
     * 发票 code 901
     */
    INVOICE_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.INVOICE.getCode(), "enum.aiAssistantPushType.name.invoice_push", "aiAssistantInvoicePush", 0, ""),

    /**
     * 付款计划 801
     */
    PAY_PLAN_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.PAY_PLAN.getCode(), "enum.aiAssistantPushType.name.pay_plan_push", "aiAssistantPayPlanPush", 0, ""),


    //******************************************jxc***********************************************//

    /**
     * 供应商 code 1001
     */
    SUPPLIER_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.SUPPLIER.getCode(), "enum.aiAssistantPushType.name.supplier_push", "aiAssistantSupplierPush", 0, ""),
    /**
     * 供应商联系人 code 1002
     */
    SUPPLIER_CONTACT_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.SUPPLIER_CONTACT.getCode(), "enum.aiAssistantPushType.name.supplier_contact_push", "aiAssistantSupplierContactPush", 0, ""),

    /**
     * 采购合同 code 1101
     */
    PURCHASE_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.PURCHASE.getCode(), "enum.aiAssistantPushType.name.purchase_push", "aiAssistantPurchasePush", 0, ""),
    /**
     * 采购退货 code 1201
     */
    RETURNED_PURCHASE_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), "enum.aiAssistantPushType.name.returned_purchase_push", "aiAssistantReturnedPurchase", 0, ""),


    /**
     * 入库单 code 1401
     */
    INSTOCK_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.INSTOCK.getCode(), "enum.aiAssistantPushType.name.instock_push", "aiAssistantInstockPush", 0, ""),
    /**
     * 出库单 code 1501
     */
    OUTSTOCK_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.OUTSTOCK.getCode(), "enum.aiAssistantPushType.name.outstock_push", "aiAssistantOutstockPush", 0, ""),

    /**
     * 盘点单 code 1701
     */
    INVENTORY_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.INVENTORY.getCode(), "enum.aiAssistantPushType.name.inventory_push", "aiAssistantInventoryPush", 0, ""),

    /**
     * 调拔单 code 1601
     */
    TRANSFER_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.TRANSFER.getCode(), "enum.aiAssistantPushType.name.transfer_push", "aiAssistantTransferPush", 0, ""),
    /**
     * 出入库单 code 1301
     */
    ASSEMBLE_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.ASSEMBLE.getCode(), "enum.aiAssistantPushType.name.assemble_push", "aiAssistantAssemblePush", 0, ""),

    /**
     * Bom清单 code 2601
     */
    BOMBILL_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(),XbbRefTypeEnum.BOM_BILL.getCode(),"enum.aiAssistantPushType.name.bombill_push","aiAssistantBomBillPush",0,""),
    /**
     * 生产单 code 2801
     */
    PRODUCTION_ORDER_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), "enum.aiAssistantPushType.name.production_order_push","aiAssistantProductionOrderPush",0,""),



    //******************************************工单中心***********************************************//
    /**
     * 工单 code 2301
     */
    WORKORDER_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.WORK_ORDER.getCode(), "enum.aiAssistantPushType.name.workorder_push", "aiAssistantWorkOrderPush", 0, ""),


    /**
     * 产品 2401
     */
    PRODUCT_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.PRODUCT.getCode(), "enum.aiAssistantPushType.name.product_push", "aiAssistantProductPush", 0, ""),
    /**
     * 库存查询 1901
     */
    PRODUCT_STOCK_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.STOCK_SEARCH.getCode(), "enum.aiAssistantPushType.name.product_stock_push", "aiAssistantProductStockPush", 0, ""),
    /**
     * 库存预警 1901
     */
    PRODUCT_STOCK_WARNING_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.STOCK_SEARCH.getCode(), "enum.aiAssistantPushType.name.product_stock_warning_push", "aiAssistantStockWarningPush", 0, ""),
    /**
     * 保质期预警 1901
     */
    PRODUCT_STOCK_GUARANTEE_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.STOCK_SEARCH.getCode(), "enum.aiAssistantPushType.name.product_stock_guarantee_push", "aiAssistantProductGuaranteePush", 0, ""),
    /**
     * 待采购 1102
     */
    WAIT_PURCHASE_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.WAIT_PURCHASE.getCode(), "enum.aiAssistantPushType.name.wait_purchase_push", "aiAssistantWaitPurchasePush", 0, ""),
    /**
     * 待生产 2803
     */
    WAIT_PRODUCE_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.WAIT_PRODUCE.getCode(), "enum.aiAssistantPushType.name.wait_produce_push", "aiAssistantWaitProducePush", 0, ""),
    /**
     * 待出库 1503
     */
    WAIT_OUTSTOCK_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(), "enum.aiAssistantPushType.name.wait_outstock_push", "aiAssistantWaitOutstockPush", 0, ""),
    /**
     * 待入库 1403
     */
    WAIT_INSTOCK_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode(), "enum.aiAssistantPushType.name.wait_instock_push", "aiAssistantWaitInstockPush", 0, ""),

    //******************************************MarketManagement***********************************************//
    /**
     * 市场活动 8100
     */
    MARKET_ACTIVITY_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.MARKET_ACTIVITY.getCode(), "enum.aiAssistantPushType.name.market_activity_push", "aiAssistantMarketActivityPush", 0, ""),
    /**
     * 销售线索 8000
     */
    CLUE_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.CLUE.getCode(), "enum.aiAssistantPushType.name.clue_push", "aiAssistantCluePush", 0, ""),
    /**
     * 自定义表单
     */
    PAAS_PUSH(XbbRefTypeEnum.AI_ASSISTANT.getCode(), XbbRefTypeEnum.PAAS.getCode(), "enum.aiAssistantPushType.name.paas_push", "aiAssistantPaasPush", 0, ""),
    /**
     * code 404
     */
    UNKNOWN(XbbRefTypeEnum.UNKNOWN.getCode(), 0, "enum.aiAssistantPushType.name.unknown", "unknown", 0, ""),
    ;
    /** 枚举值 -- 推送类型标识*/
    private final int		code;

    /** 枚举值 -- 推送子类型标识*/
    private final int		subCode;

    /** 枚举信息--推送名称*/
    private final String    name;

    /** 枚举描述 --角色使用时状态*/
    private final String	alias;

    /** 枚举描述 --是否实时推送*/
    private final int	isRealTime;

    /** 枚举描述 --钉钉文档中的推送类型*/
    private final String	ddPushType;

    /**
     * 构造一个<code>SubModuleEnum</code>枚举对象
     *
     * @param code 类型
     * @param subCode 子类型
     * @param name 中文名
     * @param alias 英文名
     * @param isRealTime 是否实时推送
     * @param ddPushType 推送类型
     */
    AiAssistantPushTypeEnum(int code, int subCode, String name,String alias, int isRealTime, String ddPushType) {
        this.code = code;
        this.subCode = subCode;
        this.name = name;
        this.alias = alias;
        this.isRealTime = isRealTime;
        this.ddPushType = ddPushType;
    }

    /**
     * 通过枚举<code>alias</code>获得枚举
     *
     * @param alias 英文名
     * @return WxErrorCodeEnum
     */
    public static AiAssistantPushTypeEnum getByAlias(String alias) {
        for (AiAssistantPushTypeEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code 英文名
     * @return WxErrorCodeEnum
     */
    public static AiAssistantPushTypeEnum getByCode(Integer code) {
        for (AiAssistantPushTypeEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     *
     * @return List<WxErrorCodeEnum>
     */
    public List<AiAssistantPushTypeEnum> getAllEnum() {
        List<AiAssistantPushTypeEnum> list = new ArrayList<>();
        for (AiAssistantPushTypeEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    /**
     * 获取全部枚举
     *
     * @param type 类型
     * @return List<WxErrorCodeEnum>
     */
    public static List<AiAssistantPushTypeEnum> getAllEnumByType(Integer type) {
        List<AiAssistantPushTypeEnum> list = new ArrayList<>();
        for (AiAssistantPushTypeEnum cache : values()) {
            if(cache.getCode() == type){
                list.add(cache);
            }
        }

        for (int i = 0; i < list.size(); i++) {
            for (int j = i+1; j < list.size(); j++) {
                AiAssistantPushTypeEnum enumEntity;
                if (list.get(j).getSubCode() < list.get(i).getSubCode()) {
                    enumEntity = list.get(i);
                    list.set(i, list.get(j));
                    list.set(j, enumEntity);
                }
            }

        }
        return list;
    }

    /**
     * 获取全部枚举值
     *
     * @return List<String>
     */
    public List<String> getAllEnumAlis() {
        List<String> list = new ArrayList<>();
        for (AiAssistantPushTypeEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache.getAlias());
        }
        return list;
    }

    /**
     * Description:根据subCode获取枚举
     * @param subCode 子类型
     * @author 魏荣杰
     * @date 2018/7/23 8:42
     * @since v3.25
     */
    public static AiAssistantPushTypeEnum getPushTypeBySubCode(Integer subCode) {
        for (AiAssistantPushTypeEnum cache : values()) {
            if (cache.getSubCode() == subCode) {
                return cache;
            }
        }
        return UNKNOWN;
    }

    /**
     * Description: 根据code获取所有的subcode
     * @param code code
     * @return java.util.List<java.lang.Integer>
     * @author 魏荣杰
     * @date 2019/1/7 20:15
     * @since v1.0
     */
    public static List<Integer> getPushSubCodeListByCode(Integer code) {
        List<Integer> subCodes = new ArrayList<>();
        for (AiAssistantPushTypeEnum cache : values()) {
            if (Objects.equals(cache.getCode(), code)) {
                subCodes.add(cache.getSubCode());
            }
        }
        return subCodes;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
